/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hoaptt.helper;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import javax.swing.JButton;
import javax.swing.JFrame;

public class RoundButton extends JButton  {

    Shape shape;
    Coordinate loc;

    public Coordinate getLoc() {
        return loc;
    }

    public void setLoc(Coordinate loc) {
        this.loc = loc;
    }



    public RoundButton(String label, Coordinate loc) {
        super(label);
        this.loc = loc;
        Dimension size = getPreferredSize();
        size.width = size.height = Math.max(size.width,
                size.height);
        setPreferredSize(size);
        setContentAreaFilled(false);
    }

    @Override
    protected void paintComponent(Graphics g) {
        if (getModel().isArmed()) {
            g.setColor(Color.RED);
        } else {
            g.setColor(getBackground());
        }
        
        g.fillOval(0, 0, getSize().width - 1,
                getSize().height - 1);
        
        //g.fillOval(5, 5, 100, 100);

        super.paintComponent(g);
    }

    @Override
    protected void paintBorder(Graphics g) {
        g.setColor(getForeground());
        g.drawOval(0, 0, getSize().width - 1,
                getSize().height - 1);
    }
    
    @Override
    public boolean contains(int x, int y) {
        if (shape == null
                || !shape.getBounds().equals(getBounds())) {
            shape = new Ellipse2D.Float(0, 0,
                    getWidth(), getHeight());
        }
        return shape.contains(x, y);
    }

// Test routine.
    public static void main(String[] args) {
// Create a button with the label "Jackpot".
        Coordinate location = new Coordinate(1, 2);
        JButton button = new RoundButton("Jackpot", location);
        button.setBackground(Color.green);

// Create a frame in which to show the button.
        JFrame frame = new JFrame();
        frame.getContentPane().setBackground(Color.yellow);
        frame.getContentPane().add(button);
        frame.getContentPane().setLayout(new FlowLayout());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(600, 800);
        frame.setVisible(true);
    }
}